import json

from fastapi import HTTPException

from llm.ai_proxy import generateText
from schemas.ai import AIResponse


def generateContent(question: str):
    try:
        res = generateText(question)

        data = json.loads(res)

        message = data['choices'][0]['message']
        content = message['content']

        return AIResponse(result="AI Answer Completed",
                          answer=content)
    except Exception as e:
        raise HTTPException(status_code=500, detail=e.__str__())
